<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page language="java" import="ants.util.WeiBoUtil" %>
<%@ page language="java" import="weibo4j.http.*" %>
<%@ page language="java" import=" weibo4j.model.*" %>
<%@ page language="java" import=" ants.util.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String code=request.getParameter("code");
StatusWapper statusWapper=null;
if(code !=null){
	session.setAttribute("accessToken",WeiBoUtil.getAccessTokenByCode(code));
}
if(session.getAttribute("accessToken") ==null){
	response.sendRedirect( "./login.jsp "); 
	return;

}else{
	statusWapper=WeiBoUtil.getFriendsTimeline((AccessToken)session.getAttribute("accessToken"));	
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
     <title>Ants Weibo Demo</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
   
    <meta name="viewport" content="width=device-width,height=device-height, initial-scale=1, maximum-scale=1.5">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
    <jsp:include page='/common/include.jsp' />
    
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
    	var a=<%=statusWapper %>;
    	alert(a);
    </script>
  </head>
  
  <body>
   
    <div data-role="page" id="indexPage">
    	<header data-role="header"  data-position="fixed" data-fullscreen="true">
    	    <a href="#updateStatus">发布新微薄</a>    	
    		<h1>微博主页</h1>
    		<a href="javascript:history.go(0);">刷新微博</a>    
    	</header>
    	<div data-role="content">
    	
    		<ul data-role="listview" >
    		<%
    			if(statusWapper != null){
		    		for(Status s : statusWapper.getStatuses()){
		    			User user=s.getUser();
			%>
				<li>
					<a class="weibo_content">
				        <img src="<%=user.getAvatarLarge() %>" />
				        <h3><%=user.getName() %></h3>
				        <p><%=s.getText() %></p>
				        <p class="ui-li-aside"><%=AntsUtil.formatDate(s.getCreatedAt(),AntsUtil.DATE_FORMAT_STRING) %></p>
				        <div name="hideMessage" style="display:none">
			        	<p><%=s.getMid() %></p>
			     		</div>
			        </a>
					
			        <ul>
				            <li><a class="write_comment_class" href="#write_comment" >回复</a></li>
				            <li><a class="repost" href="#repost">转发</a></li>
				            <li><a   href="#indexPage" class="ui-btn-right">回到首页</a></li>
				    </ul>
				    
			    </li>
			<%		
					}
    			}
    		%>
    		</ul>
    	</div>
    	<div data-role="footer">
    		<h1>make by Ants</h1>
    	</div>
    </div>
    
    
    <div data-role="page" id="write_comment">
    	<header data-role="header" data-position="fixed" data-fullscreen="true">
    		<h1>回复</h1>
    		 <a   href="#indexPage" class="ui-btn-left">回到首页</a>
    		  <a  data-role="button" class="ui-btn-right" data-inline="true" href="javascript:$('#comment_form')[0].submit();"  >提交</a>
    	</header>
    	<div data-role="content">
    	
	    	<form id="comment_form" action="../servlet/CommentServlet" method="post">
		   			<div data-role="fieldcontain">
					    <label for="comments">回复内容</label>
					    <textarea  cols="40" rows="20" name="comments" id="comments" required="required" autofocus  placeholder="请输入内容"></textarea>
					</div>
					<div data-role="fieldcontain">
					    <input  id="mid" name="mid"  type="hidden"/>
					</div>
					<!-- 
					<div style="text-align:center;vertical-align:middle;" >
					   <a  data-role="button" data-inline="true" href="javascript:$('#comment_form')[0].submit();"  >提交</a>
					</div>
					 -->
					
			</form>
    	
    	</div>
    	<div data-role="footer">
    		<h1>make by Ants</h1>
    	</div>
    </div>
    
    <div data-role="page" id="repost">
    	<header data-role="header" data-position="fixed" data-fullscreen="true">
    		<h1>转发</h1>
    		 <a  href="#indexPage" class="ui-btn-left">回到首页</a>
    		 <a  data-role="button" class="ui-btn-right" data-inline="true" href="javascript:$('#repost_form')[0].submit();"  >提交</a>
    	</header>
    	<div data-role="content">
    	
	    	<form id="repost_form" action="../servlet/RepostServlet" method="post">
		   			<div data-role="fieldcontain">
					    <label for="comments">转发内容</label>
					    <textarea  cols="40" rows="20" name="comments" id="comments" required="required" autofocus></textarea>
					</div>
					<div data-role="fieldcontain">
					    <input  id="mid" type="hidden" name="mid"/>
					</div>
					
			</form>
    	
    	</div>
    	<div data-role="footer">
    		<h1>make by Ants</h1>
    	</div>
    </div>
    
    <div data-role="page" id="updateStatus">
    	<header data-role="header" data-position="fixed" data-fullscreen="true">
    	 <a data-rel="back" href="#indexPage" class="ui-btn-left">回到首页</a>
    		<h1>发布新微博</h1>
    	 <a  href="javascript:updateStatus_form_onSubmit();" class="ui-btn-right">发布</a>	
    	</header>
    	<div data-role="content">
    	
	    	<form id="updateStatus_form" action="../servlet/UpdateStatusServlet" method="post">
		   			<div data-role="fieldcontain">
					    <textarea  cols="40" rows="20" name="comments" id="comments"  style= "width:   100%;   height:   70%;   overflow:   hidden;   border:   0px; " required="required" placeholder="请输入内容2"></textarea>
					</div>
					
			</form>
    	
    	</div>
    	<div data-role="footer">
    		<h1>make by Ants</h1>
    	</div>
    </div>
    
    
  </body>
</html>
